module.exports = {
  getSellReasonList () {
    const list = [...this.trackList]
    list.reverse()
    const result = []
    for (let i = 0; i < list.length; i++) {
      const item = list[i]
      if (item.type === 'setSell' && this.ifOnlyPingKongByReason) {
        result.push(item.name)
      }
      if (['setNoExecute', 'setNoSell', 'setPingKong', 'setBuy'].indexOf(item.type) !== -1) {
        return result
      }
    }
    return result
  },
  getBuyReasonList () {
    const list = [...this.trackList]
    list.reverse()
    const result = []
    for (let i = 0; i < list.length; i++) {
      const item = list[i]
      if (item.type === 'setBuy' && this.ifOnlyPingKongByReason) {
        result.push(item.name)
      }
      if (['setNoExecute', 'setNoBuy', 'setPingDuo', 'setSell'].indexOf(item.type) !== -1) {
        return result
      }
    }
    return result
  },
  getBuyReasonResultList () {
    const list = this.getBuyReasonList()
    if (this.hasDuoPosition) {
      return [...new Set([...this.btbReasonList, ...list])]
    } else {
      return list
    }
  },
  getSellReasonResultList () {
    const list = this.getSellReasonList()
    if (this.hasKongPosition) {
      return [...new Set([...this.btbReasonList, ...list])]
    } else {
      return list
    }
  },
  isInBuySellReason (data) {
    if (Array.isArray(data)) {
      return data.indexOf(this.btbItem.buy_sell_reason) !== -1
    } else {
      return [data].indexOf(this.btbItem.buy_sell_reason) !== -1
    }
  },
  /**
   * level：说明
   * 1000：极端市场
   * 900：特殊比如reason-3
   * 800：小时级别
   * 100：reason
   * @returns {boolean}
   */
  // 是否覆盖原因
  ifCoverBtbBuySellReason () {
    // 等于也覆盖，相当于同级别
    if (this.sell && this.hasKongPosition && this.directionLevel < (this.btbItem.direction_level || 0)) {
      return false
    }
    if (this.buy && this.hasDuoPosition && this.directionLevel < (this.btbItem.direction_level || 0)) {
      return false
    }
    // 默认是要覆盖的
    return true
  },
  initIfOnlyPingKongByReason () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('sellIfOnlyPingByReason')) {
        return true
      }
      if (this.btbItem.buy_sell_reason.startsWith('sellIfStepBack')) {
        return true
      }
    }
    return false
  },
  initIfOnlyPingDuoByReason () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('buyIfOnlyPingByReason')) {
        return true
      }
      if (this.btbItem.buy_sell_reason.startsWith('buyIfStepBack')) {
        return true
      }
    }
    return false
  },
  initIfSellReverseTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('sellIfReverseTrend')) {
        return true
      }
    }
    return false
  },
  initIfSellPreReverseTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('sellIfPreReverseTrend')) {
        return true
      }
    }
    return false
  },
  initIfSellPrePositiveTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('sellIfPrePositiveTrend')) {
        return true
      }
    }
    return false
  },
  initIfBuyReverseTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('buyIfReverseTrend')) {
        return true
      }
    }
    return false
  },
  initIfBuyPreReverseTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('buyIfPreReverseTrend')) {
        return true
      }
    }
    return false
  },
  initIfBuyPrePositiveTrend () {
    if (this.btbItem.buy_sell_reason) {
      if (this.btbItem.buy_sell_reason.startsWith('buyIfPrePositiveTrend')) {
        return true
      }
    }
    return false
  },
  isBtbInReason (text) {
    if (this.btbItem.buy_sell_reason === text) {
      return true
    }
    if (this.buyReason === text) {
      return true
    }
    if (this.sellReason === text) {
      return true
    }
    return false
  }
}
